<template>
  <div class="m-p-20">
    <div style="width:100%;margin:10px 0">
      <el-button type="primary" @click="onSubmit">新增</el-button>
    </div>
    <TheFormCreate
      ref="theFormCreate"
      :api="()=>{}"
      mainKey="id"
      :options="formOptions"
      :form.sync="form"
    ></TheFormCreate>
  </div>
</template>
  <script>
const prefix = {
  WL: "物料spu前缀",
  ZH: "组合商品编码前缀",
  CGRK: "采购入库订单编码前缀",
  CGTH: "采购退货编码前缀",
  CG: "采购订单编码前缀",
  CGTHCK: "采购退货出库编码前缀",
  DBRK: "调拨入库订单编码前缀",
  DBCK: "调拨出库订单编码前缀",
  DB: "调拨订单编码前缀",
  PC: "入库批次前缀",
  CK: "仓库编码前缀"
};
export default {
  data() {
    const _this = this;
    const codeCheck = (rule, value, callback, required) => {
      if (!required) {
        callback();
      }
      if (value) {
        let findIndex = {};
        Object.keys(prefix).some(key => {
          if (value.indexOf(key) === 0) {
            findIndex = { key, value: prefix[key] };
          }
        });
        if (findIndex.key) {
          callback(
            new Error(
              `编码不合法，禁止以${findIndex["value"]}:${findIndex["key"]}开头`
            )
          );
        } else {
          callback();
        }
      } else {
        callback();
      }
    };
    return {
      formOptions: [
        {
          type: "input",
          field: "stockLibraryCode",
          title: "仓库编码",
          default: "",
          rules: [
            {
              validator: (rule, value, callback) =>
                codeCheck(rule, value, callback, !this.form.stockLibraryId),
              trigger: "blur"
            }
          ]
        },
        {
          type: "date",
          field: "date1",
          title: "date2",
          default: "",
          dateType: "date"
        },
        {
          type: "time",
          field: "time",
          title: "time",
          default: ""
        },
        { type: "input", field: "libraryName", title: "仓库名称", default: "" },
        {
          type: "select",
          field: "type",
          title: "仓库类型",
          default: "",
          options: [
            { value: "0", label: "自有仓" },
            { value: "1", label: "自营门店" },
            { value: "2", label: "加盟门店" }
          ]
        },
        {
          type: "cascader",
          field: "addrList",
          title: "仓库地址",
          default: "",
          separator: "-",
          labels: ["province", "city", "libraryAddressDetail"]
        },
        {
          type: "textarea",
          field: "libraryAddressDetail",
          title: "地址详情",
          default: ""
        },
        {
          type: "radio",
          field: "radio",
          title: "radio",
          default: "",
          options: [
            { value: "0", label: "自有仓" },
            { value: "1", label: "自营门店" },
            { value: "2", label: "加盟门店" }
          ]
        },
        {
          type: "checkbox",
          field: "checkbox",
          title: "checkbox",
          default: [],
          options: [
            { value: "0", label: "自有仓" },
            { value: "1", label: "自营门店" },
            { value: "2", label: "加盟门店" }
          ]
        },
        {
          type: "switch",
          field: "switch",
          title: "switch",
          default: "",
          activeText: "sss",
          inactiveText: "ddd"
        }
      ],
      form: {},
      
    };
  },
  mounted() {},
  methods: {
    onSubmit({ values }) {
      this.$refs.theFormCreate.open({ id: row.stockLibraryId });
    }
  }
};
</script>
  
  